package _go

func verifyPostorder(postorder []int) bool {
	lens := len(postorder)
	if lens <= 2 {
		return true
	}
	//先假设为后续遍历
	//获取根节点
	root := postorder[lens-1]

	//找到左子树
	var key int = 0
	for k, v := range postorder {
		if v >= root {
			key = k
			break
		}
	}
	l := postorder[:key]
	r := postorder[key : lens-1]

	for _, v2 := range r {
		if v2 < root {
			return false
		}
	}

	return verifyPostorder(l) && verifyPostorder(r)
}
